package com.qsl.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qsl.model.system.SysOperLog;
import com.qsl.model.vo.SysOperLogQueryVo;
import com.qsl.system.mapper.SysOperLogMapper;
import com.qsl.system.service.SysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements SysOperLogService {

    @Autowired
    private SysOperLogMapper sysOperLogMapper;

    /**
     * 条件分页查询
     *
     * @param page
     * @param limit
     * @param OperLogVo
     * @return
     */
    @Override
    public IPage<SysOperLog> selectPage(Integer page, Integer limit, SysOperLogQueryVo OperLogVo) {
        Page<SysOperLog> pageParam = new Page<>(page, limit);

        // 条件判断
        QueryWrapper<SysOperLog> qw = new QueryWrapper<>();
        if (!StringUtils.isEmpty(OperLogVo.getTitle())) {
            qw.like("title", OperLogVo.getOperName());
        }
        if (!StringUtils.isEmpty(OperLogVo.getOperName())) {
            qw.like("oper_name", OperLogVo.getOperName());
        }
        if (!StringUtils.isEmpty(OperLogVo.getCreateTimeBegin())) {
            qw.ge("create_time", OperLogVo.getCreateTimeBegin());
        }
        if (!StringUtils.isEmpty(OperLogVo.getCreateTimeEnd())) {
            qw.le("create_time", OperLogVo.getCreateTimeEnd());
        }
        qw.orderByDesc("id");//倒序查询
        IPage<SysOperLog> pagaModel = sysOperLogMapper.selectPage(pageParam, qw);

        return pagaModel;
    }

    // 新增
    @Override
    public void saveSysLog(SysOperLog sysOperLog) {
        sysOperLogMapper.insert(sysOperLog);
    }
}
